package com.company.cloud.pay.modules.alipay;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.DefaultSignChecker;
import com.alipay.api.domain.AlipayTradePagePayModel;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;

public class Test {
	
	
	public  static  void t() {
//		AliPayApiConfig aliPayApiConfig=new AliPayApiConfigKit();
		
		String appId="2021002128601544";
		String serviceUrl="https://openapi.alipay.com/gateway.do";
		String privateKey="MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDFEe4w86d8nkaox/s/D3ad/nv3SFA5T1MNGBzSBU/fXUMTIq5aYg69r3yMmIGF7vdqSIzp5TIwpbxf1vYxmonWcN55C0yykqxg5QLmLtYB+bLeaxmsmxwL4GVaDUL+Rt4CGEf6XowEn02DgIf552W9piv5GnG/QNZ6qFKrT5DsN0DQsT3f1856uoSJAw9GGrdQ+MLg74iK4D6WoyVCeRELUlkjchoLoKY1hJsHcnoEH14U+jac7HMjCktBf8pw9vsBJ8BEWQj8MRA1bR/yjCUYQ/f9x0f7CQcS7monGvEckX3t4YaiuGMMfUWn22mYeE/LzqWFliTBL5KGx8cM27tRAgMBAAECggEBAIzj4sywhb98ULv+LUvKPF18QRhrZJ90bMXhxUkJby8buAaINup7TFqkiYDiz0b3r38W21ek+pr5ApHqVxzjhUQAca1MPMs2PXMQh2AVf/7ti8mj/DkAs65yAUO+U3UDKVmKDnua+LOdSIeJbq1ll8Fcefefxk6bhjsu99tuCQg2vz6m8XjRTO/NrlIOlvlaNdkpgHtcQWnbGnwH5YraIpG8Lp8bEhz1vioYFNGpvTj+vviNIx1CA0VO6JDO64TrPdkFFSa0baxqARSDjH864aoGjZ52lXsRvvscvYTUkTbEL+wZGOB4stnszyxgz4GAsoZ0OZwMv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ICCzw2UsGYA3ST/eYcfPRG4rRfGYHqSrNJZ2Nmx0XQAMidMa/M96BCxKV+z4SU/SLuFGTG7yupobtVGer8UHi+BmyghymVa0uejAXB4StgUL2mixJMMMaxbyjLDVbQ+f3uKNrawGaqUptHstp5IvkSHArLV6MAEwVIxE47oTFOLS56dKJgzZPjxMoyzp6QIDAQAB";
		
		AliPayApiConfig aliPayApiConfig=
		AliPayApiConfig.builder()
			.setAppId(appId)
			.setServiceUrl(serviceUrl)
			.setCharset("utf-8")
			.setSignType("RSA2")
			.setPrivateKey(privateKey)
			.setAliPayPublicKey(alipayPublicKey).build();
		AliPayApiConfigKit.setThreadLocalAliPayApiConfig(aliPayApiConfig);
		
//		AliPayApi.
//		
//		AliPayApiConfigKit.removeThreadLocalAppId();
		
		
		AlipayTradePagePayModel model =new AlipayTradePagePayModel();
		
		model.setOutTradeNo("A0000001"); //
		model.setProductCode("FAST_INSTANT_TRADE_PAY");
		model.setTotalAmount("1"); //
		model.setSubject("测试商品");
		model.setGoodsType("1"); //
		
		
		AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
        request.setBizModel(model);
        request.setNotifyUrl("bbb");
        request.setReturnUrl("www");
        try {
			String form = AliPayApi.pageExecute(request).getBody();
			System.out.println(form);
		} catch (AlipayApiException e) {
			e.printStackTrace();
		}
		
		

		
		
		return ;
	}

	
	public static void main(String[] args) {
//		alipayClient alipayClient = 
		
//		AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
		
		String appId="2021002128601544";
		
		String privateKey="MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDFEe4w86d8nkaox/s/D3ad/nv3SFA5T1MNGBzSBU/fXUMTIq5aYg69r3yMmIGF7vdqSIzp5TIwpbxf1vYxmonWcN55C0yykqxg5QLmLtYB+bLeaxmsmxwL4GVaDUL+Rt4CGEf6XowEn02DgIf552W9piv5GnG/QNZ6qFKrT5DsN0DQsT3f1856uoSJAw9GGrdQ+MLg74iK4D6W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ipayClient alipayClient=new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",appId,
				privateKey,"json","utf-8",alipayPublicKey,"RSA2");
		
		
		
		DefaultSignChecker s=new DefaultSignChecker(alipayPublicKey);
		
//		s.check(sourceContent, signature, signType, charset)
		
		
//		
//		
//		AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
//		request.setBizContent("{" +
//		"\"out_trade_no\":\"20150320010101001\"," +
//		"\"product_code\":\"FAST_INSTANT_TRADE_PAY\"," +
//		"\"total_amount\":88.88," +
//		"\"subject\":\"Iphone6 16G\"," +
//		"\"body\":\"Iphone6 16G\"," +
//		"\"time_expire\":\"2016-12-31 10:05:01\"," +
//		"      \"goods_detail\":[{" +
//		"        \"goods_id\":\"apple-01\"," +
//		"\"alipay_goods_id\":\"20010001\"," +
//		"\"goods_name\":\"ipad\"," +
//		"\"quantity\":1," +
//		"\"price\":2000," +
//		"\"goods_category\":\"34543238\"," +
//		"\"categories_tree\":\"124868003|126232002|126252004\"," +
//		"\"body\":\"特价手机\"," +
//		"\"show_url\":\"http://www.alipay.com/xxx.jpg\"" +
//		"        }]," +
//		"\"passback_params\":\"merchantBizType%3d3C%26merchantBizNo%3d2016010101111\"," +
//		"\"extend_params\":{" +
//		"\"sys_service_provider_id\":\"2088511833207846\"," +
//		"\"hb_fq_num\":\"3\"," +
//		"\"hb_fq_seller_percent\":\"100\"," +
//		"\"industry_reflux_info\":\"{\\\\\\\"scene_code\\\\\\\":\\\\\\\"metro_tradeorder\\\\\\\",\\\\\\\"channel\\\\\\\":\\\\\\\"xxxx\\\\\\\",\\\\\\\"scene_data\\\\\\\":{\\\\\\\"asset_name\\\\\\\":\\\\\\\"ALIPAY\\\\\\\"}}\"," +
//		"\"card_type\":\"S0JP0000\"" +
//		"    }," +
//		"\"goods_type\":\"0\"," +
//		"\"timeout_express\":\"90m\"," +
//		"\"promo_params\":\"{\\\"storeIdType\\\":\\\"1\\\"}\"," +
//		"\"royalty_info\":{" +
//		"\"royalty_type\":\"ROYALTY\"," +
//		"        \"royalty_detail_infos\":[{" +
//		"          \"serial_no\":1," +
//		"\"trans_in_type\":\"userId\"," +
//		"\"batch_no\":\"123\"," +
//		"\"out_relation_id\":\"20131124001\"," +
//		"\"trans_out_type\":\"userId\"," +
//		"\"trans_out\":\"2088101126765726\"," +
//		"\"trans_in\":\"2088101126708402\"," +
//		"\"amount\":0.1," +
//		"\"desc\":\"分账测试1\"," +
//		"\"amount_percentage\":\"100\"" +
//		"          }]" +
//		"    }," +
//		"\"sub_merchant\":{" +
//		"\"merchant_id\":\"2088000603999128\"," +
//		"\"merchant_type\":\"alipay: 支付宝分配的间连商户编号, merchant: 商户端的间连商户编号\"" +
//		"    }," +
//		"\"merchant_order_no\":\"20161008001\"," +
//		"\"enable_pay_channels\":\"pcredit,moneyFund,debitCardExpress\"," +
//		"\"store_id\":\"NJ_001\"," +
//		"\"disable_pay_channels\":\"pcredit,moneyFund,debitCardExpress\"," +
//		"\"qr_pay_mode\":\"1\"," +
//		"\"qrcode_width\":100," +
//		"\"settle_info\":{" +
//		"        \"settle_detail_infos\":[{" +
//		"          \"trans_in_type\":\"cardAliasNo\"," +
//		"\"trans_in\":\"A0001\"," +
//		"\"summary_dimension\":\"A0001\"," +
//		"\"settle_entity_id\":\"2088xxxxx;ST_0001\"," +
//		"\"settle_entity_type\":\"SecondMerchant、Store\"," +
//		"\"amount\":0.1" +
//		"          }]," +
//		"\"settle_period_time\":\"7d\"" +
//		"    }," +
//		"\"invoice_info\":{" +
//		"\"key_info\":{" +
//		"\"is_support_invoice\":true," +
//		"\"invoice_merchant_name\":\"ABC|003\"," +
//		"\"tax_num\":\"1464888883494\"" +
//		"      }," +
//		"\"details\":\"[{\\\"code\\\":\\\"100294400\\\",\\\"name\\\":\\\"服饰\\\",\\\"num\\\":\\\"2\\\",\\\"sumPrice\\\":\\\"200.00\\\",\\\"taxRate\\\":\\\"6%\\\"}]\"" +
//		"    }," +
//		"\"agreement_sign_params\":{" +
//		"\"personal_product_code\":\"GENERAL_WITHHOLDING_P\"," +
//		"\"sign_scene\":\"INDUSTRY|CARRENTAL\"," +
//		"\"external_agreement_no\":\"test\"," +
//		"\"external_logon_id\":\"13852852877\"," +
//		"\"sign_validity_period\":\"2m\"," +
//		"\"third_party_type\":\"PARTNER\"," +
//		"\"buckle_app_id\":\"1001164\"," +
//		"\"buckle_merchant_id\":\"268820000000414397785\"," +
//		"\"promo_params\":\"{\\\"key\\\",\\\"value\\\"}\"" +
//		"    }," +
//		"\"integration_type\":\"PCWEB\"," +
//		"\"request_from_url\":\"https://\"," +
//		"\"business_params\":\"{\\\"data\\\":\\\"123\\\"}\"," +
//		"\"ext_user_info\":{" +
//		"\"name\":\"李明\"," +
//		"\"mobile\":\"16587658765\"," +
//		"\"cert_type\":\"IDENTITY_CARD\"," +
//		"\"cert_no\":\"362334768769238881\"," +
//		"\"min_age\":\"18\"," +
//		"\"fix_buyer\":\"F\"," +
//		"\"need_check_info\":\"F\"" +
//		"    }" +
//		"  }");
//		AlipayTradePagePayResponse response;
//		try {
//			response = alipayClient.pageExecute(request);
//			System.out.println("++++++++++++++++++");
//			System.out.println(response.getBody());
//			System.out.println("++++++++++++++++++");
//			System.out.println(JSON.toJSONString(response));
//			if(response.isSuccess()){
//				System.out.println("调用成功");
//			} else {
//				System.out.println("调用失败");
//			}
//		} catch (AlipayApiException e) {
//			e.printStackTrace();
//		}
		
       Test.t();
		
		
	}
}
